﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/AdminDefault.Master" AutoEventWireup="true"
  CodeBehind="UserList.aspx.cs" Inherits="ITViet.Web.Admin.UserList" Title="" %>

<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxHiddenField" TagPrefix="dxhf" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dxcb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div>
    <dxwgv:ASPxGridView ID="gvUser" runat="server" AutoGenerateColumns="False" ClientInstanceName="gvUser"
      KeyFieldName="Id" Width="100%" OnCustomCallback="gvUser_CustomCallback" 
      OnCustomJSProperties="gvUser_CustomJSProperties" 
      oncommandbuttoninitialize="gvUser_CommandButtonInitialize">
      <SettingsBehavior AllowDragDrop="False" AllowGroup="False" AllowSort="False" />
      <Images>
        <CollapsedButton Height="12px" Width="11px" />
        <DetailCollapsedButton Height="9px" Width="9px" />
        <HeaderFilter Height="18px"
          Width="18px" />
        <HeaderActiveFilter Height="18px"
          Width="18px" />
        <FilterRowButton Height="13px" Width="13px" />
        <CustomizationWindowClose Height="17px" Width="17px" />
        <PopupEditFormWindowClose Height="17px" Width="17px" />
        <FilterBuilderClose Height="17px" Width="17px" />
      </Images>
      <ClientSideEvents EndCallback="function(s, e) {
	ongvUser_EndCallback(s,e);
}" />
      <Columns>
        <dxwgv:GridViewDataTextColumn VisibleIndex="0" Width="40px">
          <DataItemTemplate>
            <img src="../images/delete.png" onclick="onDelete('<%#Eval("Username") %>')" style="cursor: pointer"
              alt="" />
            <img src="../images/edit.png" onclick="onEdit('<%#Eval("Username") %>','<%#Eval("Username") %>','<%#ParseHtml(Eval("Fullname")) %>','<%#Eval("Status") %>','<%#Eval("Email") %>','<%#Eval("CreatedDate") %>','<%#ParseHtml(Eval("CreatedBy")) %>')"
              style="cursor: pointer;" alt="" />
          </DataItemTemplate>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="Username" Caption="<%$ Resources:Strings, Username %>"
          VisibleIndex="1">
          <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="Fullname" VisibleIndex="2" Caption="<%$Resources:Strings, FullName %>">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataComboBoxColumn FieldName="Status" VisibleIndex="3" Caption="<%$Resources:Strings, Status %>">
          <PropertiesComboBox ValueType="System.String" DataSourceID="xdsStatus" TextField="Value"
            ValueField="Id">
          </PropertiesComboBox>
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataComboBoxColumn>
        <dxwgv:GridViewDataTextColumn FieldName="Email" VisibleIndex="4" Caption="<%$Resources:Strings, Email %>">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="CreatedDate" VisibleIndex="6" Visible="False">
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="CreatedUser" VisibleIndex="6" Visible="False">
        </dxwgv:GridViewDataTextColumn>
      </Columns>
      <StylesEditors>
        <ProgressBar Height="25px">
        </ProgressBar>
      </StylesEditors>
    </dxwgv:ASPxGridView>
  </div>
  <div style="padding-top: 5px;">
    <dxe:ASPxButton ID="btnAdd" runat="server" Text="<%$ Resources:Strings, Add %>" AutoPostBack="False">
      <ClientSideEvents Click="function(s, e) {
	onAdd();e.processOnServer = false;
}" />
    </dxe:ASPxButton>
  </div>
  <div>
    <dxpc:ASPxPopupControl ID="pcEditUser" ClientInstanceName="pcEditUser" runat="server"
      Width="400px" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
      HeaderText="<%$ Resources:Strings,UserInfo %>" CloseAction="CloseButton" Modal="True">
      <SizeGripImage Height="12px" Width="12px" />
      <SizeGripImage Height="12px" Width="12px"></SizeGripImage>
      <ContentCollection>
        <dxpc:PopupControlContentControl>
          <div>
            <dxe:ASPxLabel ID="lblErrorMessage" ClientInstanceName="lblErrorMessage" runat="server"
              Font-Bold="True" ForeColor="#FF3300">
            </dxe:ASPxLabel>
          </div>
          <table style="padding: 10px 0 0 20px; width: 100%">
            <tr>
              <td>
                <asp:Label ID="Label1" runat="server" Text="<%$Resources:Strings, Username %>"></asp:Label>
                :
              </td>
              <td width="20">
                &nbsp;
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtUsername" runat="server" ClientInstanceName="txtUsername"
                  Width="170px">
                  <ValidationSettings>
                    <ErrorImage Height="14px" />
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label2" runat="server" Text="<%$Resources:Strings, Password %>"></asp:Label>
                :
              </td>
              <td>
                &nbsp;
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtDefaultPassword" runat="server" ClientInstanceName="txtDefaultPassword"
                  Password="True" Width="170px">
                  <ValidationSettings>
                    <ErrorImage Height="14px" />
                  </ValidationSettings>
                </dxe:ASPxTextBox>
                <dxe:ASPxHyperLink ID="hlxResetPassword" runat="server" ClientInstanceName="hlxResetPassword"
                  Text="<%$ Resources:Strings, ResetPassword %>">
                  <ClientSideEvents Click="function(s,e){onResetPassword();}" />
                </dxe:ASPxHyperLink>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label4" runat="server" Text="<%$Resources:Strings, FullName %>"></asp:Label>
                :
              </td>
              <td>
                &nbsp;
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtFullName" runat="server" ClientInstanceName="txtFullName"
                  Width="170px">
                  <ValidationSettings>
                    <ErrorImage Height="14px" />
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label6" runat="server" Text="<%$ Resources:Strings, Email %>"></asp:Label>
                :
              </td>
              <td>
                &nbsp;
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtEmail" runat="server" ClientInstanceName="txtEmail" Width="170px">
                  <ValidationSettings>
                    <ErrorImage Height="14px" />
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label7" runat="server" Text="<%$ Resources:Strings, Status %>"></asp:Label>
                :
              </td>
              <td>
                &nbsp;
              </td>
              <td>
                <dxe:ASPxComboBox ID="cbxStatus" runat="server" ClientInstanceName="cbxStatus" DataSourceID="xdsStatus"
                  TextField="Value" ValueField="Id" ValueType="System.String">
                  <ButtonStyle Width="13px">
                  </ButtonStyle>
                  <ValidationSettings>
                    <ErrorImage Height="14px" Width="14px" />
                  </ValidationSettings>
                </dxe:ASPxComboBox>
              </td>
            </tr>
            <tr>
              <td style="padding-top: 4px;">
                <asp:Label ID="Label8" runat="server" Text="<%$ Resources:Strings, CreatedDate %>"></asp:Label>
                :
              </td>
              <td style="padding-top: 4px;">
                &nbsp;
              </td>
              <td style="padding-top: 4px;">
                <dxe:ASPxLabel ID="lblCreatedDate" runat="server" ClientInstanceName="lblCreatedDate"
                  Font-Bold="True">
                </dxe:ASPxLabel>
              </td>
            </tr>
            <tr style="padding-top: 4px;">
              <td style="padding-top: 4px;">
                <asp:Label ID="Label9" runat="server" Text="<%$ Resources:Strings, CreatedBy %>"></asp:Label>
                :
              </td>
              <td style="padding-top: 4px;">
                &nbsp;
              </td>
              <td style="padding-top: 4px;">
                <dxe:ASPxLabel ID="lblCreatedBy" runat="server" ClientInstanceName="lblCreatedBy"
                  Font-Bold="True">
                </dxe:ASPxLabel>
              </td>
            </tr>
            <tr>
              <td>
              </td>
              <td>
                &nbsp;
              </td>
              <td style="padding-top: 4px;">
                <div style="float: left;">
                  <dxe:ASPxButton ID="btnSave" runat="server" AutoPostBack="False" Text="<%$ Resources:Strings, Save %>">
                    <ClientSideEvents Click="function(s, e) {
	onSave();
}" />
                  </dxe:ASPxButton>
                </div>
                <div style="float: left; padding-left: 3px;">
                  <dxe:ASPxButton ID="btnCancel" runat="server" AutoPostBack="False" Text="<%$ Resources:Strings, Cancel %>">
                    <ClientSideEvents Click="function(s, e) {
	onCancel(); e.processOnServer = false;
}" />
                  </dxe:ASPxButton>
                </div>
              </td>
            </tr>
            <tr>
              <td>
                <asp:HiddenField ID="hfUserId" runat="server" />
              </td>
              <td>
                &nbsp;
              </td>
            </tr>
          </table>
        </dxpc:PopupControlContentControl>
      </ContentCollection>
      <CloseButtonImage Height="17px" Width="17px" />
      <HeaderStyle>
        <Paddings PaddingTop="1px" PaddingLeft="10px" PaddingRight="6px" />
      </HeaderStyle>
    </dxpc:ASPxPopupControl>
  </div>
  <div>
    <asp:XmlDataSource ID="xdsStatus" runat="server" XPath="Items/CommonStatus/Status"
      DataFile="~/App_Data/Status.xml"></asp:XmlDataSource>
    <asp:HiddenField ID="hfCurrentUser" runat="server" />
    <asp:HiddenField ID="hfDefaultPassword" runat="server" />
    <dxcb:ASPxCallback ID="ctrlCallback" ClientInstanceName="ctrlCallback" runat="server"
      OnCallback="ctrlCallback_Callback">
      <ClientSideEvents CallbackComplete="function(s,e){ctrCallback_CallbackComplete(s,e);}" />
    </dxcb:ASPxCallback>
  </div>

  <script type="text/javascript" language="javascript">
    function onEdit(id, username, fullName, status, email, createdDate, createdUser) {
      var para = createdDate.split(' ');
      txtUsername.SetText(username);
      txtUsername.SetEnabled(false);
      txtFullName.SetText(fullName);
      cbxStatus.SetValue(status);
      txtEmail.SetText(email);
      lblCreatedDate.SetText(para[0]);
      lblCreatedBy.SetText(createdUser);
      showResetPassword(true);
      document.getElementById('<%=hfUserId.ClientID %>').value = id;
      lblErrorMessage.SetText('');
      pcEditUser.Show();
    }

    function onDelete(userId) {
      if (confirm('<%=GetGlobalResourceObject("Messages", "ERR0006") %>'))
        gvUser.PerformCallback('Delete|' + userId);
    }

    function onAdd() {
      resetValue();
      pcEditUser.Show();
    }

    function onSave() {
      if (validateInput())
        gvUser.PerformCallback('Save|');
    }

    function onResetPassword() {
      ctrlCallback.SendCallback('ResetPassword|');
    }

    function onCancel() {
      showResetPassword(false);
      pcEditUser.Hide();
    }

    function resetValue() {
      txtUsername.SetText('');
      txtUsername.SetEnabled(true);
      txtDefaultPassword.SetText(document.getElementById('<%=hfDefaultPassword.ClientID %>').value);
      txtFullName.SetText('');
      txtEmail.SetText('');
      cbxStatus.SetValue('A');
      var now = new Date();
      lblCreatedDate.SetText(now.getDate() + '/' + (now.getMonth() + 1) + '/' + now.getFullYear());
      lblCreatedBy.SetText(document.getElementById('<%=hfCurrentUser.ClientID %>').value);
      document.getElementById('<%=hfUserId.ClientID %>').value = '';
      lblErrorMessage.SetText('');
    }

    function validateInput() {
      var error = '';
      if (txtUsername.GetText() == '')
        error += '<BR> + <%=(string)GetGlobalResourceObject("Strings", "Username") %>';
      if (txtUsername.GetText() == '')
        error += '<BR> + <%=(string)GetGlobalResourceObject("Strings", "DefaultPassword") %>';
      if (txtFullName.GetText() == '')
        error += '<BR> + <%=(string)GetGlobalResourceObject("Strings", "FullName") %>';
      if (error == '' && txtEmail.GetText() != '' && !ValidateEmail(txtEmail.GetText())) {
        error = '<%=(string)GetGlobalResourceObject("Messages", "ERR0029") %>';
        lblErrorMessage.SetText(error);
        return false;
      }
      if (error != '') {
        error = '<%=(string)GetGlobalResourceObject("Messages", "ERR0008") %>' + error;
        lblErrorMessage.SetText(error);
        return false;
      }
      return true;
    }

    function showResetPassword(show) {
      hlxResetPassword.SetVisible(show);
      txtDefaultPassword.SetVisible(!show);
    }

    function ongvUser_EndCallback(s, e) {
      var error = gvUser.cpInnerError.split('|');
      if (error[0] == 'Save') {
        if (error[1] != '')
          lblErrorMessage.SetText(error[1]);
        else {
          pcEditUser.Hide();
          alertMessage('<%=(string)GetGlobalResourceObject("Messages", "ERR0005") %>');
        }
      }
    }

    function ctrCallback_CallbackComplete(s, e) {
      pcEditUser.Hide();
      alertMessage(e.result);
    }
  </script>

</asp:Content>
